#
#  Product controller
#

from dzutil import message
from views.product_view import *
from models.product import Products, Product

#------------------------------------------------------------------------
class ProductController:

    def _index(self):
		return ProductListView()

    def _show(self,key):
		return ProductShowView(key)

    def _edit(self,key):
		return ProductEditView(key)

    def _confirm_delete(self,key):
		return ProductDeleteView(key)

    def _delete(self,PRODUCTID,yes_button):
        import dzutil
        products = Products()
        product = products.seek(PRODUCTID)
        products.delete(product)
        message('Deleted %s' % product.title)
        return ProductListView()

    def _add(self):
        return ProductAddView()

    def _update(self,PRODUCTID,**args):
        products = Products()
        product = products.seek(PRODUCTID)
        product.update(args)
        products.update(product)
        message('Updated')
        return ProductShowView(PRODUCTID)

    def _insert(self,**args):
        products = Products()
        product = products.new()
        product.update(args)
        newid = products.insert(product)
        message('Added')
        return ProductShowView(newid)


result = ProductController()

